package com.hsh;

import org.apache.logging.log4j.LogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author: shaohai.huang
 * @date: 2020-03-26
 */
public class Foo {
    private static Logger logger = LoggerFactory.getLogger(Foo.class);

    public static void main(String[] args) throws IOException {

        //-Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
//        System.setProperty("log4j2.contextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
//        System.setProperty("-Dlog4j2.contextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
//        System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
//        if (logger.isErrorEnabled()) {
//            logger.error("error test {} {}", "p1", "p2");
//        }
//        logger.error("error test");vv
//        logger.warn("warn {}", "p1");v
//        System.out.println("-------------------end");
//        try {
//            int x = 1 / 0;
//        } catch (Exception e) {
//            logger.warn("warn {}", e);
//            throw new ZeusIdException("test");
//        }


        Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    logger.error("error test " + i);
                }
                System.out.println("-------print end");
            }
        }, 5, 5, TimeUnit.SECONDS);

//        logger.info("test1");
//        System.out.println("foo thread name " + Thread.currentThread().getName());
        System.out.println(System.in.read());
    }
}
